package com.gdth.bank.widget.baiduMap;

import com.baidu.mapapi.map.BaiduMap;

import com.baidu.mapapi.search.core.RouteLine;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.route.BikingRouteResult;
import com.baidu.mapapi.search.route.DrivingRouteResult;
import com.baidu.mapapi.search.route.IndoorRouteResult;
import com.baidu.mapapi.search.route.MassTransitRouteResult;
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
import com.baidu.mapapi.search.route.TransitRouteResult;
import com.baidu.mapapi.search.route.WalkingRouteResult;


/**
 * 设置途径点以及resetEndNode会回调该接口
 * @author mac1
 *
 */
public class BOnGetRoutePlanResultListener implements OnGetRoutePlanResultListener{
	
	private BaiduMap mBaiduMap;
	
	private boolean useDefaultIcon;
	
	public BOnGetRoutePlanResultListener(boolean useDefaultIcon, BaiduMap mBaiduMap){
		this.useDefaultIcon = useDefaultIcon;
		
		this.mBaiduMap = mBaiduMap;
	}

	@Override
	public void onGetBikingRouteResult(BikingRouteResult arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onGetDrivingRouteResult(DrivingRouteResult arg0) {
		// TODO Auto-generated method stub
		if (arg0 == null || arg0.error != SearchResult.ERRORNO.NO_ERROR) {
			mRouteCallBack.showError("抱歉，未找到结果");
        }
        if (arg0.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
            //起终点或途经点地址有岐义，通过以下接口获取建议查询信息
            //result.getSuggestAddrInfo()
            return;
        }
        if (arg0.error == SearchResult.ERRORNO.NO_ERROR) {
            DrivingRouteOverlay overlay = new BDrivingRouteOverlay(mBaiduMap, useDefaultIcon);
            RouteLine<?> route = arg0.getRouteLines().get(0);
        	mRouteCallBack.updateView(overlay, route);

            overlay.setData(arg0.getRouteLines().get(0));
            overlay.addToMap();
            overlay.zoomToSpan();
        }
	}

	@Override
	public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) {

	}

	@Override
	public void onGetTransitRouteResult(TransitRouteResult arg0) {
		// TODO Auto-generated method stub
		if (arg0 == null || arg0.error != SearchResult.ERRORNO.NO_ERROR) {
			mRouteCallBack.showError("抱歉，未找到结果");
        } else if (arg0.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
            //起终点或途经点地址有岐义，通过以下接口获取建议查询信息
            //result.getSuggestAddrInfo()
            return;
        } else if (arg0.error == SearchResult.ERRORNO.NO_ERROR) {
            TransitRouteOverlay overlay = new BTransitRouteOverlay(mBaiduMap, useDefaultIcon);
            RouteLine<?> route = arg0.getRouteLines().get(0);
        	mRouteCallBack.updateView(overlay, route);
            overlay.setData(arg0.getRouteLines().get(0));
            overlay.addToMap();
            overlay.zoomToSpan();
        }
	}

	@Override
	public void onGetMassTransitRouteResult(MassTransitRouteResult massTransitRouteResult) {

	}

	@Override
	public void onGetWalkingRouteResult(WalkingRouteResult arg0) {
		// TODO Auto-generated method stub
		if (arg0 == null || arg0.error != SearchResult.ERRORNO.NO_ERROR) {
			mRouteCallBack.showError("抱歉，未找到结果");
        }
        if (arg0.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
            //起终点或途经点地址有岐义，通过以下接口获取建议查询信息
            //result.getSuggestAddrInfo()
            return;
        }
        if (arg0.error == SearchResult.ERRORNO.NO_ERROR) {
            WalkingRouteOverlay overlay = new BWalkingRouteOverlay(mBaiduMap, useDefaultIcon);
            RouteLine<?> route = arg0.getRouteLines().get(0);
            mRouteCallBack.updateView(overlay, route);
        	
            overlay.setData(arg0.getRouteLines().get(0));
            overlay.addToMap();
            overlay.zoomToSpan();
        }
	}
	
	private RouteCallBack mRouteCallBack;
	
	public void setRouteCallBack(RouteCallBack mRouteCallBack){
		this.mRouteCallBack = mRouteCallBack;
	}
	
	public interface RouteCallBack{
		void updateView(OverlayManager mOverlayManager, RouteLine<?> route);
		
		void showError(String msg);
	}
}
